package org.qpcr.community.project.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum InterpretationOperator {
    GREATER_THAN(1, "GREATER_THAN", "大于"),
    LESS_THAN(2, "LESS_THAN", "小于"),
    GREATER_THAN_OR_EQUAL(3, "GREATER_THAN_OR_EQUAL", "大于等于"),
    LESS_THAN_OR_EQUAL(4, "LESS_THAN_OR_EQUAL", "小于等于"),
    EQUAL(5, "EQUAL", "等于"),
    NOT_EQUAL(6, "NOT_EQUAL", "不等于"),
    BETWEEN(7, "BETWEEN", "在...之间"),
    NOT_BETWEEN(8, "NOT_BETWEEN", "不在...之间"),;

    private final int code;
    private final String name;
    private final String label;

    public static InterpretationOperator fromCode(Integer code) {
        for (InterpretationOperator op : values()) {
            if (op.code == code) return op;
        }
        throw new IllegalArgumentException("未知操作符编码: " + code);
    }

    public static InterpretationOperator fromName(String name) {
        for (InterpretationOperator op : values()) {
            if (op.name().equals(name) || op.getName().equals(name)) return op;
        }
        throw new IllegalArgumentException("未知操作符: " + name);
    }
}